package com.ckjava.test.web;

import com.ckjava.test.entity.TaskMain;
import com.ckjava.test.service.TaskMainService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@Api
@RequestMapping(value = "/api")
public class TaskMainController {

	@Autowired
    private TaskMainService taskMainService;

    @RequestMapping(value = "/task_main", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    @ResponseBody
    public List<TaskMain> getAll() {
        return taskMainService.getAll();
    }
    
    @RequestMapping(value = "/task_main", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String saveOne(@RequestBody TaskMain taskMain) {
    	taskMain.setCreateDate(new Date());
        return taskMainService.saveOne(taskMain);
    }
    
    @RequestMapping(value = "/task_main", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
    public void updateOne(@RequestBody TaskMain taskMain) {
        taskMainService.updateOne(taskMain);
    }
    
    @RequestMapping(value = "/task_main/{id}", method = RequestMethod.DELETE, produces = "application/json;charset=utf-8")
    public int deleteOne(@PathVariable String id) {
        return taskMainService.deleteOne(id);
    }
    
    @RequestMapping(value = "/task_main/{id}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    public TaskMain getOne(@PathVariable String id) {
        return taskMainService.getOne(id);
    }
}
